package com.hg.hggood.controller;

import com.hg.hggood.util.JsonResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@RestController
public class RedirectController extends BaseController{

    @RequestMapping({"xlogin","xregister","xpermain","xchangepsw","xperdata","xuploadavatar",
            "xrecmanage","xhomepage","xBindPhone","productdetails","cart","createorder","pay",
            "orderlist", "orderdetail",

            "PxReg","PxLogin","PxPersionMain","PxChangePsw","PxChangeInfo",
            "PxChangeAdd","PxOrderList","PxOrderDetails","PxCart","PxCreateOrder",
            "PxPay","PxProductDetails","PxMain","PxTake_outTest","PxJudgeIFPay"})
    public JsonResult<String> redirect(
            HttpServletResponse response,
            HttpServletRequest request,
            HttpSession session
    ) throws IOException {
        session.setAttribute("uri",request.getRequestURI());
        response.sendRedirect("/");
        return null;
    }

    @RequestMapping("gogogo")
    public JsonResult<String> gogogo(HttpSession session){
        String data = (String) session.getAttribute("uri");
        System.out.println(data);
        return new JsonResult<String>(OK,data);
    }
}
